package com.hhkj.study.admin.resource.service.extend.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.hhkj.study.admin.course.enums.CourseAssocResourceTypeEnum;
import com.hhkj.study.admin.resource.entity.ResourceCourseBase;
import com.hhkj.study.admin.resource.entity.ResourceCourseVideo;
import com.hhkj.study.admin.resource.model.podo.ResourceCourseVideoDo;
import com.hhkj.study.admin.resource.model.podo.ResourceCourseVideoPo;
import com.hhkj.study.admin.resource.service.base.ResourceCourseVideoService;
import com.hhkj.study.admin.resource.service.extend.ResourceCourseBaseExtendService;
import com.hhkj.study.admin.resource.service.extend.ResourceCourseVideoExtendService;
import com.ruoyi.common.base.biz.service.extend.BaseExtendServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
*
* @author SERVER
* @since 2024-09-06
*/
@Service
public class ResourceCourseVideoExtendServiceImpl extends BaseExtendServiceImpl<ResourceCourseVideo, ResourceCourseVideoDo, ResourceCourseVideoPo, ResourceCourseVideoService>
        implements ResourceCourseVideoExtendService, ResourceCourseBaseExtendService {
    @Override
    public ResourceCourseVideo getByNameCourseType(String name, Long courseType) {
        LambdaQueryWrapper<ResourceCourseVideo> courseVideoQuery = new LambdaQueryWrapper<>();
        courseVideoQuery.eq(ResourceCourseVideo::getName, name).eq(ResourceCourseVideo::getCourseType, courseType).last("LIMIT 1");
        return this.getService().getOne(courseVideoQuery);
    }

    @Override
    public CourseAssocResourceTypeEnum getCourseResourceTypeEnum() {
        return CourseAssocResourceTypeEnum.VIDEO;
    }

    @Override
    public List<ResourceCourseVideoPo> listByIdList(Collection<Long> idList) {
        if (CollectionUtil.isEmpty(idList)) {
            return Lists.newArrayList();
        }
        ResourceCourseVideoDo resourceCourseVideoDo = new ResourceCourseVideoDo();
        resourceCourseVideoDo.setIdList(Lists.newArrayList(idList));
        return this.getService().listPoByDo(resourceCourseVideoDo);
    }

    @Override
    public List<ResourceCourseVideo> getResouceListByIdList(Collection<? extends Serializable> idList, List<? extends ResourceCourseBase> resourceList) {
        if (CollectionUtil.isEmpty(idList) || CollectionUtil.isEmpty(resourceList)) {
            return Lists.newArrayList();
        }
        List<ResourceCourseVideo> resourceCourseList =  BeanUtil.copyToList(resourceList, ResourceCourseVideo.class);
        return resourceCourseList.stream().filter(e -> idList.contains(e.getId())).collect(Collectors.toList());
    }


    @Override
    public boolean saveBatchVideoNameUnique(List<ResourceCourseVideo> resourceCourseVideoList) {
        if (CollectionUtil.isEmpty(resourceCourseVideoList)) {
            return false;
        }
        return this.getService().saveBatch(resourceCourseVideoList);
    }
}
